namespace Defiant.SqlServer.PowerShellScriptTask
{
    using System;

    using Microsoft.SqlServer.Dts.Design;
    using Microsoft.SqlServer.Dts.Runtime;
    using Microsoft.SqlServer.Dts.Runtime.Design;

    public sealed class PowerShellTaskUI : IDtsTaskUI
    {
        private TaskHost taskHost;

        private PowerShellScriptTask task;

        private IServiceProvider serviceProvider;

        #region IDtsTaskUI Members

        public void Delete(System.Windows.Forms.IWin32Window parentWindow)
        {
        }

        public System.Windows.Forms.ContainerControl GetView()
        {
            if (this.taskHost == null)
            {
                throw new Exception("Task host wasn't initialized");
            }


            return new PowerShellEditor(this.taskHost);
        }

        public void Initialize(TaskHost host, IServiceProvider serviceProvider)
        {
            if (host == null)
            {
                throw new ArgumentNullException("host");
            }
            if (!(host.InnerObject is PowerShellScriptTask))
            {
                throw new ArgumentOutOfRangeException("host", "The task host isn't the expected type");
            }

            this.taskHost = host;
            this.task = (PowerShellScriptTask)host.InnerObject;
            this.serviceProvider = serviceProvider;
        }

        public void New(System.Windows.Forms.IWin32Window parentWindow)
        {
        }

        #endregion
    }
}
